package org.example.elm_xiangmu.mapper;

import org.apache.ibatis.annotations.*;
import org.example.elm_xiangmu.po.Cart;

import java.util.List;

@Mapper
public interface CartMapper {
    @Select("select * from cart where userId = #{userId}")
    List<Cart> listCartAll(String userId);

    @Select("select * from cart where userId = #{userId} and businessId = #{businessId} and quantity > 0")
    List<Cart> listCartByBusinessId(String userId, Integer businessId);

    @Insert("insert into cart (foodId,businessId,userId,quantity) values (#{foodId},#{businessId},#{userId},#{quantity})")
    void saveCart(Cart cart);

    @Update("update cart set quantity = #{quantity} where businessId = #{businessId} and foodId = #{foodId} and userId = #{userId}")
    void updateCart(Cart cart);

    @Delete("delete from cart where businessId = #{businessId} and foodId = #{foodId} and userId = #{userId}")
    void removeByFoodId(Cart cart);

    @Delete("delete from cart where businessId = #{businessId} and userId = #{userId}")
    void removeAll(Cart cart);
}
